home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / Pascal OS8 / Everything / ModalStuff.p < prev    next >
Encoding:
Text File  |  1998-10-30  |  3.7 KB  |  181 lines  |  [TEXT/CWIE]

  1. { ModalStuff.p -- Modal dialog }
  2. { Created 10/30/98 1:06 PM by AppMaker }
  3.  
  4. Unit ModalStuff;
  5. Interface
  6.  
  7. Uses
  8.     Types,
  9.     Quickdraw,
  10.     Controls,
  11.     Dialogs,
  12.     Events,
  13.     Lists,
  14.     Menus,
  15.     TextEdit,
  16.     DModalStuffData,
  17.     AMDialog;
  18.  
  19. type
  20.     CModalStuff        = object (AMDialog)
  21.  
  22.     {data members}
  23.         mData:        DModalStuffData;
  24.  
  25.     mOKHandle:        ControlHandle;
  26.     mToolsHandle:        ControlHandle;
  27.     mPopupsHandle:        ControlHandle;
  28.     mFromValuesList2Handle:        ControlHandle;
  29.     mFromMenuHandle:        ControlHandle;
  30.     mListsHandle:        ControlHandle;
  31.     mTextListHandle:        ControlHandle;
  32.  
  33.     {methods - public}
  34.         Procedure ConnectToData    (inData:    AMSignaler); Override;
  35.  
  36.     {methods - internal}
  37.         Procedure FinishMake; Override;
  38.         Procedure DoItem    (inItemHit:    SInt16); Override;
  39.         Procedure DataChanged    (inDataID:    longint); Override;
  40.  
  41.     end;
  42.  
  43. {----------}
  44. Function NewModalStuff: CModalStuff;
  45.  
  46. {----------}
  47. Function GetModalStuff    (ioData:    DModalStuffData): Boolean;
  48.  
  49. {----------}
  50. Implementation
  51.  
  52. Uses
  53.     ResourceDefs,
  54.     ControlUtils,
  55.     Miscellany;
  56.  
  57. const
  58.     kOKButton        = 1;
  59.     kToolsPalette        = 2;
  60.     kPopupsBox        = 3;
  61.     kFromValuesList2Popup        = 4;
  62.     kFromMenuPopup        = 5;
  63.     kListsBox        = 6;
  64.     kTextListList        = 7;
  65.  
  66. {    Procedure BuildTextListList    (inControl:        ControlHandle);    }
  67.  
  68. {----------}
  69. Procedure BuildTextListList (
  70.     inControl:        ControlHandle);
  71. var
  72.     list:        ListHandle;
  73. begin
  74.     list := GetListHandle (inControl);
  75.     AddToList ("One",   list);
  76.     AddToList ("Two",   list);
  77.     AddToList ("Three", list);
  78.     AddToList ("Infinity",  list);
  79.  
  80. end; {BuildTextListList}
  81.  
  82. {----------}
  83. Function NewModalStuff: CModalStuff;
  84. var
  85.     dialog:        CModalStuff;
  86. begin
  87.     dialog := nil;
  88.     New (dialog);
  89.  
  90.     if dialog <> nil then begin
  91.         dialog.Initialize;
  92.     end;
  93.     NewModalStuff := dialog;
  94. end;
  95.  
  96. {----------}
  97. Function GetModalStuff (
  98.     ioData:        DModalStuffData): Boolean;
  99. Var
  100.     result:            Boolean;
  101.     dialog:            CModalStuff;
  102. begin
  103.     result := false;
  104.     dialog := NewModalStuff;
  105.  
  106.     result := dialog.RunModal (DLOG_ModalStuff, ioData);
  107.  
  108.     dialog.Free;
  109.     Dispose (dialog);
  110.  
  111.     GetModalStuff := result;
  112. end;
  113.  
  114. {----------}
  115. Procedure CModalStuff.FinishMake;
  116. var
  117.     errCode:        OSErr;
  118. begin
  119.     mOKHandle := GetControlItem (kOKButton);
  120.     SetDefaultState (mOKHandle, true);
  121.     errCode := SetDialogDefaultItem (mDialog, kOKButton);
  122.     mToolsHandle := GetControlItem (kToolsPalette);
  123.     mPopupsHandle := GetControlItem (kPopupsBox);
  124.     mFromValuesList2Handle := GetControlItem (kFromValuesList2Popup);
  125.     mFromMenuHandle := GetControlItem (kFromMenuPopup);
  126.     mListsHandle := GetControlItem (kListsBox);
  127.     mTextListHandle := GetControlItem (kTextListList);
  128. end;
  129.  
  130. {----------}
  131. Procedure CModalStuff.ConnectToData (
  132.     inData:        AMSignaler); Override;
  133. begin
  134.     inherited ConnectToData (inData);
  135.     mData := DModalStuffData (inData);
  136.  
  137.     SetControlValue (mToolsHandle, mData.GetTools2);
  138.     SetControlValue (mFromValuesList2Handle, mData.GetFromValuesList3);
  139.     SetControlValue (mFromMenuHandle, mData.GetFromMenu2);
  140.     BuildTextListList (mTextListHandle);
  141.     SetListBoxChoice (mTextListHandle, mData.GetTextList2);
  142. end;
  143.  
  144. {----------}
  145. Procedure CModalStuff.DoItem (
  146.     inItemHit:        SInt16);
  147. begin
  148.     case inItemHit of
  149.     kOKButton:
  150.             SetResult (true);
  151.     kToolsPalette:
  152.             mData.SetTools2 (GetControlValue (mToolsHandle));
  153.     kFromValuesList2Popup: begin
  154.             mData.SetFromValuesList3 (GetControlValue (mFromValuesList2Handle));
  155.         end;
  156.     kFromMenuPopup: begin
  157.             mData.SetFromMenu2 (GetControlValue (mFromMenuHandle));
  158.         end;
  159.     kTextListList:
  160.             mData.SetTextList2 (GetListBoxChoice (mTextListHandle));
  161.  
  162.     end; {switch}
  163. end;
  164.  
  165. {----------}
  166. Procedure CModalStuff.DataChanged (
  167.     inDataID:        longint); Override;
  168. begin
  169.     if inDataID = idTools2 then begin
  170.         SetControlValue (mToolsHandle, mData.GetTools2);
  171.     end;
  172.     if inDataID = idFromValuesList3 then begin
  173.         SetControlValue (mFromValuesList2Handle, mData.GetFromValuesList3);
  174.     end;
  175.     if inDataID = idFromMenu2 then begin
  176.         SetControlValue (mFromMenuHandle, mData.GetFromMenu2);
  177.     end;
  178. end;
  179.  
  180. End.
  181.